//
//  ConfirmAnOrderVC.m
//  phmall
//
//  Created by admin on 2017/12/12.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "ConfirmAnOrderVC.h"
#import "OrderCell.h"
#import "AddressView.h"
#import "DetailsModel.h"
#import "PaymentView.h"
#import "paymentModel.h"
#import "ShippingAddressVC.h"
#import "OrderdetailVC.h"
#import "Ipay88PayVC.h"
#import "OrderModel.h"
@interface ConfirmAnOrderVC ()<UITableViewDelegate,UITableViewDataSource,PaymentViewDelegate,ShippingAddressVCDelegate>{
    UIView *headerView;
    UIImageView *background;
    PaymentView *pay;
    AddressView *address;
}
@property(strong,nonatomic)UITableView *myTableview;
@property(nonatomic,strong)MBProgressHUD *hud;
@property(nonatomic,strong)NSMutableArray *payArray;
@property(nonatomic,strong)paymentModel *payModel;
@property(nonatomic,assign)BOOL payType;
@end

@implementation ConfirmAnOrderVC
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.barTintColor = [UIColor  whiteColor];
    //导航栏字体和颜色
    NSMutableDictionary *navDic=@{}.mutableCopy;
    navDic[NSFontAttributeName]=[UIFont systemFontOfSize:20];
    navDic[NSForegroundColorAttributeName]=[UIColor blackColor];
    [self.navigationController.navigationBar setTitleTextAttributes:navDic];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=Localized(@"确认订单");
    UIBarButtonItem* leftBar=[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(leftBarAction)];
    self.navigationItem.leftBarButtonItem=leftBar;
    
    [self.view addSubview:self.myTableview];
    [self.myTableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(0);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view).with.offset(self.tabBar_height-49);
    }];
    [self addFooterView];
    //整体界面
    headerView=[UIView new];
    headerView.backgroundColor=[UIColor groupTableViewBackgroundColor];
    
    address=[[AddressView alloc]init];
    [headerView addSubview:address];
    
    YYCache *cache = [YYCache cacheWithName:@"address"];
    if ([cache containsObjectForKey:@"default"]) {
        NSMutableDictionary *index = (NSMutableDictionary *)[cache objectForKey:@"default"];
        AddressModel *mdoel=[AddressModel yy_modelWithDictionary:index];
        address.model=mdoel;
    }
    
    [address mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.bottom.equalTo(address.decorate.mas_bottom).offset(1);
        make.bottom.equalTo(headerView.mas_bottom).offset(-10).priorityHigh();
    }];
    [address layoutIfNeeded];
    
    
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectAddress)];
    [headerView addGestureRecognizer:tap];
    
    UILabel *line=[UILabel new];
    line.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [headerView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(headerView.mas_bottom).offset(0);
        make.left.equalTo(headerView).with.offset(0);
        make.right.equalTo(headerView).with.offset(0);
        make.height.mas_equalTo(1);
    }];

    //添加webview前计算一次高度
    CGFloat height = [headerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    CGRect frame = headerView.bounds;
    frame.size.height = height;
    headerView.frame = frame;
    [self.myTableview setTableHeaderView:headerView];
    [headerView layoutIfNeeded];
    // Do any additional setup after loading the view.
}
-(void)selectAddress{
    self.hidesBottomBarWhenPushed=YES;
    ShippingAddressVC *favorite=[[ShippingAddressVC alloc]init];
    favorite.order=YES;
    [self.navigationController pushViewController:favorite animated:YES];
    favorite.delegate=self;
}
-(void)SelectAddress:(AddressModel *)model{
    address.model=model;
}
-(void)addFooterView{
    //底部背景
    UIView *footerView=[UIView new];
    footerView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:footerView];
    
    [footerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).offset(-self.tabBar_height);
        make.left.right.offset(0);
        make.height.offset(49);
    }];
    
    NSInteger allPrice = 0;
    NSInteger allnumber = 0;
    for (OrderModel *model in self.orderArray) {
        for (GoodsListModel *goodsModel in model.goods_list) {
            allPrice+=[goodsModel.rest_price doubleValue]*[goodsModel.buy_number doubleValue];
            allnumber+=[goodsModel.buy_number doubleValue];
        }
    }
    
    //立即购买
    UIButton *purchase=[UIButton buttonWithType:UIButtonTypeCustom];
    [purchase setTitle:Localized(@"提交订单") forState:UIControlStateNormal];
    [purchase addTarget:self action:@selector(purchaseAction) forControlEvents:UIControlEventTouchUpInside];
    purchase.backgroundColor=[UIColor colorWithHexString:@"#ff802a"];
    [footerView addSubview:purchase];
    purchase.titleLabel.font=[UIFont systemFontOfSize:15];
    [purchase mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(footerView);
        make.width.offset(SCREEN_WIDTH/5*2);
    }];
    
    UILabel *number=[[UILabel alloc]init];
    [footerView addSubview:number];
    number.text=[NSString stringWithFormat:@"%.0ld %@",(long)allnumber,Localized(@"件商品")];
    number.font=[UIFont systemFontOfSize:10];
    [number mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.bottom.offset(0);
        make.height.offset(21);
    }];
   
    
    UILabel *price=[[UILabel alloc]init];
    [footerView addSubview:price];
    price.text=[NSString stringWithFormat:@"%@:₱%.2ld",Localized(@"合计"),(long)allPrice];
    price.font=[UIFont systemFontOfSize:16];
    price.textColor=[UIColor orangeColor];
    [price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.top.offset(0);
        make.height.offset(28);
    }];
    
    UIView *line=[[UIView alloc]init];
    [footerView addSubview:line];
    line.backgroundColor=[UIColor colorWithHexString:@"#ECEBEC"];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.height.offset(0.5);
    }];
}
-(void)purchaseAction{
  
    self.hud =[MBProgressHUD showHUDAddedTo:self.view  animated:YES];
    self.hud.detailsLabel.text =  Localized(@"加载中...");
    
    NSString *urlstr =  [NSString stringWithFormat:@"%@%@",HomeURL,@"payment_list"];
    
    [httpTool ZBPostNetDataWith:urlstr withDic:nil andSuccess:^(id responseObject) {
        self.emptyType=EmptyDataSetNoData;
        
        NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        if ([responseDict[@"ret"] doubleValue] == 200) {
            if (responseDict[@"data"] !=[NSNull alloc]) {
                NSLog(@"%@",responseDict[@"data"]);
                [self analysisDataWithPaymentArray:responseDict[@"data"]];
            }
        }else{
            
        }
    
        [self choosePaymentType];
        [self.hud hideAnimated:YES];
    } andFailure:^{
        [self.hud hideAnimated:YES];
        [PublicClass ProgressHUDModeText:Localized(@"网络错误") andTime:2 ];
    }];
  
}
- (void)analysisDataWithPaymentArray:(NSMutableArray *)array{
    [self.payArray removeAllObjects];
    for (NSMutableDictionary *data in array) {
        paymentModel *model=[paymentModel yy_modelWithDictionary:data];
        [self.payArray addObject:model];
    }
}
-(void)choosePaymentType{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"支付方式" message:@"请选择支付方式" preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    for (paymentModel *model in self.payArray) {
        [alertController addAction:[UIAlertAction actionWithTitle:model.class_name style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            self.payModel=model;
            self.payType=NO;
            [self PaymentView];
        }]];
    }
    [alertController addAction:[UIAlertAction actionWithTitle:@"余额" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        self.payType=YES;
        [self balancePay];
    }]];
    [self.navigationController presentViewController:alertController animated:YES completion:nil];
    
}
-(void)balancePay{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"余额不足时使用其他方式" message:@"请选择支付方式" preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    for (paymentModel *model in self.payArray) {
        [alertController addAction:[UIAlertAction actionWithTitle:model.class_name style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            self.payModel=model;
            [self PaymentView];
        }]];
    }
    [self.navigationController presentViewController:alertController animated:YES completion:nil];
}
-(void)PaymentView{
    background=[UIImageView new];
    background.image=[UIImage imageNamed:@"透明图片"];
    [[UIApplication sharedApplication].keyWindow addSubview:background];
    [background mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.offset(0);
    }];
    //    background.hidden=YES;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(close)];
    background.userInteractionEnabled=YES;
    [background addGestureRecognizer:tap];
    
    pay=[[PaymentView alloc]init];
    pay.delegate=self;
    if (self.payType) {
        [pay.type setTitle:@"余额支付" forState:UIControlStateNormal];
    }else{
        [pay.type setTitle:self.payModel.class_name forState:UIControlStateNormal];
    }
    ViewBorderRadius(pay, 10, 0, [UIColor clearColor]);
    [[UIApplication sharedApplication].keyWindow addSubview:pay];
    [pay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.centerY.offset(-60);
        make.width.offset(280);
        make.height.offset(260);
    }];
}
-(void)close{
    background.hidden=YES;
    pay.hidden=YES;
}

-(void)Passwordill:(NSString *)Password{
    NSString *urlstr =  [NSString stringWithFormat:@"%@%@",HomeURL,@"cart_pay"];
    NSMutableDictionary *parametersDic = [NSMutableDictionary dictionary];
//
    [parametersDic setValue:address.model.province forKey:@"province"];
    [parametersDic setValue:address.model.city forKey:@"city"];
    [parametersDic setValue:address.model.county forKey:@"county"];
    [parametersDic setValue:address.model.address  forKey:@"address"];
    [parametersDic setValue:address.model.consignee forKey:@"consignee"];
    [parametersDic setValue:address.model.mobile  forKey:@"mobile"];
    [parametersDic setValue:address.model.zipcode forKey:@"zipcode"];
    if (self.payType) {
        [parametersDic setValue:@"1"  forKey:@"advance"];
    }else{
        [parametersDic setValue:@"0"  forKey:@"advance"];
    }
    
    [parametersDic setValue:Password forKey:@"pay_pass"];
    [parametersDic setValue:self.payModel.ID  forKey:@"pay_id"];
    
    for (OrderModel *model in self.orderArray) {
        NSMutableArray *goodsID=[[NSMutableArray alloc]init];
        for (GoodsListModel *goodsModel in model.goods_list) {
            [goodsID addObject:goodsModel.g_uid];
        }
        [parametersDic setValue:[goodsID componentsJoinedByString:@","] forKey:[NSString stringWithFormat:@"cart_uid[%@]",model.m_uid]];
        [parametersDic setValue:@"0"  forKey:[NSString stringWithFormat:@"memo[%@]",model.m_uid]];
        [parametersDic setValue:@""  forKey:[NSString stringWithFormat:@"invoice[%@]",model.m_uid]];
        [parametersDic setValue:@"0" forKey:[NSString stringWithFormat:@"ship_uid[%@]",model.m_uid]];
        [parametersDic setValue:@"0"  forKey:[NSString stringWithFormat:@"ship_price[%@]",model.m_uid]];
        [parametersDic setValue:@"0" forKey:[NSString stringWithFormat:@"coupon_uid[%@]",model.m_uid]];
    }

    [httpTool ZBPostNetDataWith:urlstr withDic:parametersDic andSuccess:^(id responseObject) {
        self.emptyType=EmptyDataSetNoData;
        [self close];
        NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        if ([responseDict[@"ret"] doubleValue] == 200) {
            if (responseDict[@"data"] !=[NSNull alloc]) {
                
                if ([responseDict[@"status"] isEqualToString:@"1"]) {
                    OrderModel *model = [OrderModel yy_modelWithDictionary:responseDict[@"ordersn"]];
                    if ([model.pay_id isEqualToString:@"16"]) {
                        Ipay88PayVC *ipay=[[Ipay88PayVC alloc]init];
                        ipay.payOrder=model;
                        self.hidesBottomBarWhenPushed=YES;
                        [self.navigationController pushViewController:ipay animated:YES];
                    }else{
                        [self orderPayment:model.ordersn andPassword:Password];
                    }
                    
                }else if ([responseDict[@"status"] isEqualToString:@"-1"]){
                    [PublicClass ProgressHUDModeText:@"支付密码错误" andTime:2];
                }else{
                    [PublicClass ProgressHUDModeText:@"下单失败" andTime:2];
                }
            }
        }
        [self.hud hideAnimated:YES];
    } andFailure:^{
        [self close];
        [self.hud hideAnimated:YES];
        [PublicClass ProgressHUDModeText:Localized(@"网络错误") andTime:2 ];
    }];
    
}

-(void)orderPayment:(NSString *)order_id andPassword:(NSString *)password{
    self.hud =[MBProgressHUD showHUDAddedTo:self.view  animated:YES];
    self.hud.detailsLabel.text = Localized(@"加载中...");
    
    NSString *urlstr =  [NSString stringWithFormat:@"%@%@",HomeURL,@"pay"];
    NSMutableDictionary *parametersDic = [NSMutableDictionary dictionary];
    //
    if (self.payType) {
        [parametersDic setValue:@"1" forKey:@"advance"];
    }else{
        [parametersDic setValue:@"0" forKey:@"advance"];
    }
    
    [parametersDic setValue:password forKey:@"pay_pass"];
    [parametersDic setValue:self.payModel.ID forKey:@"pay_id"];
    [parametersDic setValue:order_id forKey:@"orderid"];

    [httpTool ZBPostNetDataWith:urlstr withDic:parametersDic andSuccess:^(id responseObject) {
        self.emptyType=EmptyDataSetNoData;
        NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        if ([responseDict[@"ret"] doubleValue] == 200) {
            if (responseDict[@"data"] !=[NSNull alloc]) {
                if ([responseDict[@"status"] isEqualToString:@"1"]) {
                    [PublicClass ProgressHUDModeText:@"支付成功" andTime:2];
                }else{
                    [PublicClass ProgressHUDModeText:@"支付失败" andTime:2];
                }
    
                self.hidesBottomBarWhenPushed=YES;
                OrderdetailVC *evaluate=[[OrderdetailVC alloc]init];
                evaluate.ordersn=order_id;
                [self.navigationController pushViewController:evaluate animated:YES];

            }
        }
        [self.hud hideAnimated:YES];
    } andFailure:^{
        [self.hud hideAnimated:YES];
        [PublicClass ProgressHUDModeText:Localized(@"网络错误") andTime:2 ];
    }];
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    OrderModel *model=self.orderArray[section];
    return model.goods_list.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.orderArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    //总高度
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 44*5+4+10;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *nameView=[[UIView alloc]init];
    nameView.backgroundColor=[UIColor whiteColor];
    OrderModel *model=self.orderArray[section];
    UILabel *name=[UILabel new];
    name.text=model.shop_name;
    name.numberOfLines=2;
    name.font=[UIFont systemFontOfSize:15];
    [nameView addSubview:name];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(nameView);
        make.left.offset(10);
    }];
    
    UIImageView *leave=[[UIImageView alloc]init];
    leave.image=[UIImage imageNamed:@"前往"];
    [nameView addSubview:leave];
    [leave mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(name);
        make.width.height.offset(15);
        make.left.equalTo(name.mas_right).with.offset(5);
    }];
    
    UILabel *line=[UILabel new];
    line.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [nameView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(nameView.mas_bottom).offset(0);
        make.left.equalTo(nameView).with.offset(0);
        make.right.equalTo(nameView).with.offset(0);
        make.height.mas_equalTo(1);
    }];

    return nameView;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    OrderModel *model=self.orderArray[section];
    
    NSInteger allPrice = 0;
    NSInteger allnumber = 0;
    for (GoodsListModel *goodsModel in model.goods_list) {
        allPrice+=[goodsModel.rest_price doubleValue]*[goodsModel.buy_number doubleValue];
        allnumber+=[goodsModel.buy_number doubleValue];
    }
    
    UIView *footerView = [[UIView alloc]init];
    footerView.backgroundColor=[UIColor groupTableViewBackgroundColor];
    
    UIView *couponView=[[UIView alloc]init];
    [footerView addSubview:couponView];
    couponView.backgroundColor=[UIColor whiteColor];
    [couponView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.height.offset(44);
    }];
    
    UILabel *couponLabel=[[UILabel alloc]init];
    [couponView addSubview:couponLabel];
    couponLabel.text=Localized(@"优惠券");
    couponLabel.font=[UIFont systemFontOfSize:15];
    [couponLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.centerY.offset(0);
    }];
    
    UIButton *coupon=[UIButton buttonWithType:UIButtonTypeCustom];
    [couponView addSubview:coupon];
    [coupon setTitle:Localized(@"无 >") forState:UIControlStateNormal];
    [coupon setTitleColor:[UIColor colorWithHexString:@"#adadad"] forState:UIControlStateNormal];
    coupon.titleLabel.font=[UIFont systemFontOfSize:13];
    [coupon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.offset(0);
    }];
    
    
    UIView *expressView=[[UIView alloc]init];
    [footerView addSubview:expressView];
    expressView.backgroundColor=[UIColor whiteColor];
    [expressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(44);
        make.top.equalTo(couponView.mas_bottom).offset(1);
    }];
    
    UILabel *expressLabel=[[UILabel alloc]init];
    [expressView addSubview:expressLabel];
    expressLabel.text=Localized(@"快递方式");
    expressLabel.font=[UIFont systemFontOfSize:15];
    [expressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.centerY.offset(0);
    }];

    UIButton *express=[UIButton buttonWithType:UIButtonTypeCustom];
    [expressView addSubview:express];
    [express setTitle:Localized(@"包邮 >") forState:UIControlStateNormal];
    [express setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    express.titleLabel.font=[UIFont systemFontOfSize:13];
    [express mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.offset(0);
    }];

    UIView *freightView=[[UIView alloc]init];
    [footerView addSubview:freightView];
    freightView.backgroundColor=[UIColor whiteColor];
    [freightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(44);
        make.top.equalTo(expressView.mas_bottom).offset(1);
    }];

    UILabel *freightLabel=[[UILabel alloc]init];
    [freightView addSubview:freightLabel];
    freightLabel.text=Localized(@"运费");
    freightLabel.font=[UIFont systemFontOfSize:15];
    [freightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.centerY.offset(0);
    }];

    UIButton *freight=[UIButton buttonWithType:UIButtonTypeCustom];
    [freightView addSubview:freight];
    [freight setTitle:@"0" forState:UIControlStateNormal];
    [freight setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    freight.titleLabel.font=[UIFont systemFontOfSize:13];
    [freight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.offset(0);
    }];
//
    UIView *messageView=[[UIView alloc]init];
    [footerView addSubview:messageView];
    messageView.backgroundColor=[UIColor whiteColor];
    [messageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(44);
        make.top.equalTo(freightView.mas_bottom).offset(1);
    }];

    UILabel *messageLabel=[[UILabel alloc]init];
    [messageView addSubview:messageLabel];
    messageLabel.text=Localized(@"卖家留言");
    messageLabel.font=[UIFont systemFontOfSize:15];
    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);

        make.centerY.offset(0);
    }];
    UITextField *message=[[UITextField alloc]init];
    [messageView addSubview:message];
    message.textAlignment=NSTextAlignmentRight;
    message.placeholder=Localized(@"留言");
    message.font=[UIFont systemFontOfSize:13];
    [message mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.offset(0);
        make.left.equalTo(messageLabel.mas_right).offset(10);
    }];

    UIView *numberView=[[UIView alloc]init];
    [footerView addSubview:numberView];
    numberView.backgroundColor=[UIColor whiteColor];
    [numberView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(44);
        make.top.equalTo(messageView.mas_bottom).offset(1);
    }];

    UILabel *number=[[UILabel alloc]init];
    [numberView addSubview:number];
    number.text=[NSString stringWithFormat:@"%lu %@",allnumber,Localized(@"件商品")];
    number.font=[UIFont systemFontOfSize:15];
    [number mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.centerY.offset(0);
    }];

    UILabel *price=[[UILabel alloc]init];
    [numberView addSubview:price];
    price.text=[NSString stringWithFormat:@"%@:₱%.2ld",Localized(@"合计"),(long)allPrice];
    price.font=[UIFont systemFontOfSize:13];
    price.textColor=[UIColor orangeColor];
    [price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.offset(0);
    }];
    return footerView;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    OrderCell *cell=[OrderCell theShareCellWithTableView:tableView];
    OrderModel *model=self.orderArray[indexPath.section];
    GoodsListModel *goodsModel=model.goods_list[indexPath.row];
    cell.model=goodsModel;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    //分割线补全
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}

//MARK:-GETTER
- (UITableView *)myTableview{
    if (!_myTableview) {
        _myTableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _myTableview.delegate = self;
        _myTableview.dataSource = self;
        _myTableview.backgroundColor=[UIColor groupTableViewBackgroundColor];
        _myTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _myTableview.showsVerticalScrollIndicator=NO;
        _myTableview.scrollEnabled = YES;
    }
    return _myTableview;
}
-(NSMutableArray *)payArray{
    if (!_payArray) {
        _payArray=[[NSMutableArray alloc]init];
    }
    return _payArray;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
